import unittest

from functions import convert_cny_to_usd


class User:
    def __init__(self, id):
        self.id = id

    def __eq__(self, other):
        return self.id == other.id


class TestMethods(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        print("called once before any tests in class")

    @classmethod
    def tearDownClass(cls):
        print("\ncalled once after all tests in class")

    def setUp(self):
        print("called before each test")

    # def tearDown(self):
    #     print("called after each test")

    def test_cny_to_usd1(self):
        self.assertAlmostEqual(convert_cny_to_usd(100), 13.89, places=2)

    @unittest.skip("skip anyway")
    def test_cny_to_usd2(self):
        self.assertAlmostEqual(convert_cny_to_usd(100, 6.5), 15.38, places=2)

    @unittest.skipIf(1 + 1 == 2, "skip if true")
    def test_cny_to_usd3(self):
        self.assertAlmostEqual(convert_cny_to_usd(0), 0, places=2)

    @unittest.skipUnless(1 + 1 == 3, "skip if false")
    def test_cny_to_usd4(self):
        self.assertAlmostEqual(convert_cny_to_usd(0), 0, places=2)

    @unittest.expectedFailure
    def test_cny_to_usd5(self):
        self.assertAlmostEqual(convert_cny_to_usd(-100), -13.89, places=2)

    @unittest.expectedFailure
    def test_cny_to_usd6(self):
        self.fail("Failing this test on purpose")

    def test_object_identity(self):
        user1 = User(1)
        user2 = User(1)
        # print(id(user1), id(user2))
        self.assertIsNot(user1, user2)
        self.assertEqual(user1, user2)


if __name__ == "__main__":
    # unittest.main(defaultTest="suite")
    unittest.main()
